package com.atguigu.leetcode;

import cn.hutool.core.lang.Console;
import cn.hutool.core.util.ArrayUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

public class _4FindMedianSortedArrays {

    int[] nums1 = {};
    int[] nums2 = {1,2,3,4,5};
    @Test
    public void test() {
        double v = myFindMedianSortedArrays(nums1, nums2);
        Console.log(v);
    }

    public double myFindMedianSortedArrays(int[] nums1, int[] nums2) {
        int len = nums1.length + nums2.length;
        int[] all = new int[len];
        int cur = 0;
        for (int i = 0; i < nums1.length; i++, cur++) {
            all[cur] = nums1[i];
        }
        for (int i = 0; i < nums2.length; i++, cur++) {
            all[cur] = nums2[i];
        }
        Arrays.sort(all);
        if (all.length == 1) {
            return all[0];
        }
        if (len % 2 != 0) {
            return all[len / 2];
        }

        int temp = len / 2;
        return Double.valueOf((all[temp] + all[temp - 1])) / 2;
    }
}
